﻿using UnityEngine;
using System.Collections.Generic;

namespace GameDesigner
{
    public interface IStateMachine
    {
        RefIdentity Id { get; set; }
        string name { get; set; }
        StateMachineView View { get; set; }
        Transform transform { get; }
        State[] States { get; set; }
#if UNITY_EDITOR
        State SelectState { get; set; }
        List<int> SelectStates { get; set; }
#endif
        State DefaultState { get; set; }
        int StateId { get; set; }
        int NextId { get; set; }
        IStateMachine Parent { get; set; }
        IStateMachine Root { get; }
        IAnimationHandler Handler { get; set; }
        StateMachineUpdateMode UpdateMode { get; set; }
        IStateMachine[] SubStateMachines { get; set; }
        /// <summary>
        /// 状态机执行
        /// </summary>
        void Execute(StateMachineUpdateMode currMode);
        /// <summary>
        /// 当进入下一个状态, 你也可以立即进入当前播放的状态, 如果不想进入当前播放的状态, 使用StatusEntry方法
        /// </summary>
        /// <param name="nextStateIndex">下一个状态的ID</param>
        void EnterNextState(int nextStateIndex, int actionId = 0);
        /// <summary>
        /// 进入下一个状态, 如果状态正在播放就不做任何处理, 如果想让动作立即播放可以使用 OnEnterNextState 方法
        /// </summary>
        /// <param name="stateID"></param>
        void StatusEntry(int stateID, int actionId = 0);
        /// <summary>
        /// 切换状态
        /// </summary>
        /// <param name="stateId"></param>
        /// <param name="force"></param>
        void ChangeState(int stateId, int actionId = 0, bool force = false);
        void ChangeChildState(int stateId, int actionId = 0);
        void UpdateStates();
        void ClearStates();
        State AddState(string name, params StateBehaviour[] behaviours);
        State AddState(string name, bool actionSystem, bool animLoop, bool isCrossFade, bool isExitState, params StateBehaviour[] behaviours);
        State AddSubState(string stateName, Vector2 mousePosition = default);
        State AddParentState(string stateName, Vector2 mousePosition = default);
        State CloneState(State state);
        void Init();
#if UNITY_EDITOR
        void OnScriptReload(StateMachineView view);
#endif
        void AddSubStateMachine(State state, IStateMachine stateMachine);
        void UpdateSubStateMachineIds();
        void UpdateRefId(State state);
        void RemoveStates(State[] states);
        void RemoveSubStateMachine(State state);
    }
}
